declare

v_tmcode integer;
v_mpulknxg_id integer;
 v_seq integer;
 v_count number := 0;
 

begin

select count(*)
into v_count
from sysadm.mpulknxg
where tmcode between 2074 and 2076
and prgcode <> 4
and prgcode is not null;


if v_count = 0 then 

--mpulknxg

--check the sequence
select max(mpulknxg_id)+ 1 
into v_mpulknxg_id
from sysadm.mpulknxg;

select sysadm.max_mpulknxg_id_seq.nextval
into v_seq
 from dual;

if v_seq <= v_mpulknxg_id then
 
 for r1 in v_seq .. v_mpulknxg_id loop
 
select sysadm.max_mpulknxg_id_seq.nextval
into v_seq
 from dual;

end loop;

end if;

v_tmcode := 2074;

while v_tmcode <= 2076 loop

insert into sysadm.mpulknxg 
select SNCODE,v_tmcode,TYPEIND,PRGCODE,PLCODE,LVCODE,TM_PRG_DEF,SUBM_ID,REC_VERSION,FU_PACK_ID,AREA_ID,SPCODE,NPCODE,DNCODE, sysadm.max_mpulknxg_id_seq.nextval
from sysadm.mpulknxg 
where tmcode = 2044
and prgcode <> 4 
and prgcode is not null;
    
v_tmcode := v_tmcode + 1;    
    
end loop;

end if;

commit;

end;

